<template>
	<view class="bg">
		<u-navbar :is-back="true" title="设置" title-color="white" :background="background"></u-navbar>
		<view class="u-m-t-20">
			<ul>
				<li @click="openinfo('/pages/tabBar/my/initial')">个人资料</li>
				<li @click="openinfo('/pages/tabBar/my/Qualification')">资质证件</li>
			</ul>
		</view>
		<view class="u-m-t-20">
			<ul>
				<li @click="">绑定手机
					<span v-show='bindding.phone!=null'>
						{{bindding.phone}}
					</span>
					<span v-show="bindding.phone==''" @click="goBind('phone')">
						去绑定
					</span>
				</li>
				<li @click="">绑定微信
					<span v-show='bindding.wx==0' @click="goBind('wx')">
						去绑定
					</span>
					<span v-show='bindding.wx==1'>
						已绑定
					</span>
				</li>
				<li @click="">绑定支付宝
					<span v-show='bindding.zfb==0' @click="goBind('zfb')">
						去绑定
					</span>
					<span v-show='bindding.zfb==1'>
						已绑定
					</span>
				</li>
				<li @click="">绑定微博
					<span v-show='bindding.wb==0' @click="goBind('wb')">
						去绑定
					</span>
					<span v-show='bindding.wb==1'>
						已绑定
					</span>
				</li>
			</ul>
		</view>
		<view class="u-m-t-20">
			<ul>
				<li @click="openinfo('')">隐私设置</li>
				<li @click="openinfo('')">清楚缓存 <span>{{storageSize}}</span></li>
				<li @click="openinfo('')">检查更新<span>当前版本V1.0</span></li>
			</ul>
		</view>
		<view class="u-m-t-20">
			<ul>
				<li @click="">客服电话<span>400-686-0286</span></li>
				<li @click="">关于美蜂<span></span></li>
			</ul>
		</view>
		<u-button style="color: #2979FF;width: 90%;margin-bottom: 30rpx;">切换账号</u-button>
		<u-button style="color: #2979FF;width: 90%;margin-bottom: 30rpx;" @click="logout()">退出登录</u-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bindding: {
					phone: '',
					wx: 0,
					zfb: 0,
					wb: 0
				},



				// 缓存大小
				storageSize: '',
				background: {
					backgroundColor: '#00a8ff',
				}
			}
		},
		onShow() {
			let userInfo = uni.getStorageSync('userInfo');
			console.log(userInfo);
			this.bindding.phone = userInfo.mobile;
			this.bindding.phone = this.bindding.phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
		},
		onLoad() {
			this.getStorageSize();
			this.getWeChat();
		},
		methods: {
			getStorageSize: function() {
				let that = this;
				uni.getStorageInfo({
					success(res) {
						//console.log(res.keys);
						//console.log(res.limitSize);
						let size = res.currentSize;
						if (size < 1024) {
							that.storageSize = size + ' B';
						} else if (size / 1024 >= 1 && size / 1024 / 1024 < 1) {
							that.storageSize = Math.floor(size / 1024 * 100) / 100 + ' KB';
						} else if (size / 1024 / 1024 >= 1) {
							that.storageSize = Math.floor(size / 1024 / 1024 * 100) / 100 + ' M';
						}
					}
				})
			},
			// getWeChat
			getWeChat() {
				this.$apiVipCentre.bingwechatG({}).then((res) => {
					console.log('request data data', res.data.data);
					if (res.data.data.bind_wechat == "false") {
						console.log("没有绑定");
						this.bindding.wx = 0;
					} else {
						console.log("绑定了");
						this.bindding.wx = 1;
					}
				}).catch((err) => {
					console.log('request fail', err);
				})
			},
			// postWeChat
			postWeChat() {
				this.$apiVipCentre.bingwechatP({
					code: ''
				}).then((res) => {
					console.log('request data data', res.data.data);
				}).catch((err) => {
					console.log('request fail', err);
				})

			},
			// 去绑定事件
			goBind(tag) {
				switch (tag) {
					case 'wx':
						console.log('去绑定 wx');
						break;
					case 'zfb':
						console.log('去绑定 zfb');
						break;
					case 'wb':
						console.log('去绑定 wb');
						break;
					case 'phone':
						console.log("去绑定 phone");
						break;
				}
			},

			openinfo(url) {
				uni.navigateTo({
					url: url,
				});
			},

			// 退出登录
			logout() {
				this.$apiVipCentre.logout().then((res) => {
					console.log(res.data);
				}).catch((err) => {
					console.log(err)
				})

				uni.switchTab({
					url: '/pages/tabBar/index/index'
				})
				// 清除 所有 缓存
				uni.clearStorageSync();
			}
		}
	}
</script>

<style scoped lang="scss">
	.bg {
		background-color: #f6f6f6;
	}

	.u-m-t-20 {
		margin: 20px 0;
	}

	.u-m-t-20 li {
		padding-left: 20px;
		color: #937bb5;
		background-color: #ffffff;
		line-height: 50px;
		border-bottom: 1px solid #f4f6f8;
	}

	ul {
		list-style: none;

		padding: 2px;
	}

	.u-m-t-20 li span {
		padding-right: 20px;
		float: right;
	}
</style>
